import store from "@/store";
import request from '@/utils/request';
import { resetRouter } from "@/router";
import { removeToken } from "@/utils/auth";

/**
 * 登录
 * @param {object} data 
 */
export function login(data) {
    return request({
        url: "/user/login",
        method: "post",
        data: data
    });
}

/**
 * 注册
 * @param {object} data 
 */
export function register(data) {
    return request({
        url: "/user/register",
        method: "post",
        data: data
    })
}

/**
 * 退出：清除保存的token，重置路由，state
 */
export function logout() {
    return new Promise((resolve) => {
        removeToken();
        store.commit("user/RESET_STATE");
        resetRouter();
        resolve();
    });
}